package com.fonts;

import com.enums.TextLevEnum;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BaseFont;
import lombok.Data;

import java.io.IOException;

@Data
public class DefaultFont extends AbstractFont implements Font {
    private BaseFont baseFont;
    private com.itextpdf.text.Font oneTitleFont;
    private com.itextpdf.text.Font titleSecondFont;
    private com.itextpdf.text.Font contentFont;
    private com.itextpdf.text.Font tableCellFont;

    public DefaultFont() {
        try {
            // Font.BOLD: 加粗字体 Font.NORMAL: 正常（非加粗）字体 Font.ITALIC: 斜体  Font.ITALIC_BOLD: 斜体加粗 Font.BOLD | Font.ITALIC将创建一个既加粗又斜体的字体
            // BaseFont.EMBEDDED true嵌入pdf文件，false依赖环境是否存在字体
            this.baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            this.oneTitleFont = new com.itextpdf.text.Font(this.baseFont, 14, com.itextpdf.text.Font.BOLD);
            this.titleSecondFont = new com.itextpdf.text.Font(this.baseFont, 12, com.itextpdf.text.Font.NORMAL);
            this.contentFont = new com.itextpdf.text.Font(this.baseFont, 10, com.itextpdf.text.Font.NORMAL);
            this.tableCellFont = new com.itextpdf.text.Font(this.baseFont, 9, com.itextpdf.text.Font.NORMAL);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public com.itextpdf.text.Font getFont(TextLevEnum textLevEnum) {
        if (TextLevEnum.ONE_LEV == textLevEnum) {
            return this.oneTitleFont;
        } else if (TextLevEnum.TWO_LEV == textLevEnum) {
            return this.titleSecondFont;
        } else if (TextLevEnum.FOUR_LEV == textLevEnum) {
            return this.tableCellFont;
        }
        return this.contentFont;
    }

    @Override
    public BaseFont getBaseFont() {
        return this.baseFont;
    }

}
